package com.project.controller;

import com.project.bean.CommentBean;
import com.project.bean.UserBean;
import com.project.service.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("comment")
public class CommentController {
    @Autowired
    private ICommentService service;

    @RequestMapping("add")
    public List<CommentBean> add(String content, int commodityId, HttpServletRequest req){
        //从session中得到登陆用户
        UserBean user = (UserBean) req.getSession().getAttribute("loginUser");
        CommentBean comment = new CommentBean(user.getId(),content,commodityId);

        List<CommentBean> list = service.addComment(comment);
        return list;
    }
}
